home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / info_tip / dragdr / dragdr.txt
Encoding:
Text File  |  1994-11-07  |  3.3 KB  |  79 lines

  1. VB 3.0 Tips:
  2. Detecting End of Drag & Drops Sequences
  3. Michael D. Strathman
  4. MeV Technology, Inc.
  5.  
  6. "Drag_and_drop would be considerably easier if the Visual Basic
  7. designers had provided a simple means to determine that a drop
  8. had been unsuccessful." Gary Wisniewski, "Drag 'til you Drop",
  9. April/May 1993 BASICPro Magazine, Fawcette Technical Publications.
  10.  
  11. Microsoft in their invariable wisdom somehow chose to make the 
  12. manual DRAG function operate rather counter-intuitively.
  13. That is, when an item is droped, the Mouse_Up function for the
  14. initiating subroutine is NOT called!  This makes it very difficult
  15. to detect unsuccessful drops.  Detecting an unsuccessful drop can
  16. be of importance when you need to update animation that may be in
  17. progress to support the Drag-Drop Sequence.  To this end, this
  18. application note will suggest a very simple method for detecting
  19. the End_Of_Drag sequence.  This technique work whether the
  20. operation was successful or not. One of  its major benefits of
  21. this technique is that it does not require any custom control
  22. programming!
  23.  
  24. The method involves generating the proper Mouse_Up event at the
  25. end of the drag operation.  This can be accomplished using a
  26. single Windows API call and a normal Visual Basic Timer.
  27.  
  28. The sequence is:
  29.  
  30.       1) Enable a form timer in the Mouse_Down sequence after
  31.          any animation steps but just before starting the 
  32.          manual Drag sequence,
  33.          (remember to set the timer interval=5 or some value)
  34.          (You can rename the timer ControlMouseUp if you like)
  35.  
  36.       2) On each timer tick look to determine if the operator
  37.          has released the mouse button. 
  38.  
  39.  The steps are pretty simple:   _________________________________
  40. '*** Put a timer named ControlMouseUp on your form
  41.  
  42. '**** In a .BAS form (as you will probably use this elsewhere) Declare the API Function
  43. Declare Function GetKeyState Lib "User" (ByVal nKey As Integer) As Integer
  44.  
  45. '**** In the code sequence for the control of Interest
  46. Sub Control_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  47.  
  48.     FileCabinet = FileOpenIcon    '*** Animation, transfer image from one Box to another
  49.     Control.DragIcon = AnyIcon    '*** Set up the Drag Icon  
  50.     ControlMouseUp.Enabled = True '*** Enable the Timer (Put on the form at Design Time)
  51.     Control.Drag 1                '*** Start the manual Drag Operation
  52.  
  53. End Sub
  54.  
  55. '***** In the form Timer Event Code Section
  56. '        This is the NEW Mouse_Up Routine!
  57. Sub ControlMouseUp_Timer ()
  58.  
  59.     K% = 1               '*** Set the Virtual Scan code for the Mouse Left Button
  60.     I% = GetKeyState(K%) '*** Get the Key state
  61.     I% = I% And (Not 1)  '*** Mask off the unimportant Bits
  62.     If  I% = 0 Then      '*** Test to see if the operator has released the mouse button
  63.                                  '*** Mouse_Up Detected!     
  64.      FileCabinet = FileClosed    '*** Finish animation, by transferring images
  65.      ControlMouseUp.Enabled = 0  '*** Turn off the timer so this event will not be triggered
  66.     End If    
  67.  
  68. End Sub
  69. ______________________________________________________________
  70.  
  71. Author:
  72. Michael D. Strathman
  73. MeV Technolgy, Inc.
  74. 5150 Shadow Estates
  75. San Jose, CA 95135
  76. Ph. (408) 238-6351
  77. Fax: (408) 238-3466
  78. Compuserve: 75663,520
  79.